package com.qinghe.pro.controller.main;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qinghe.pro.entity.main.Suggest;
import com.qinghe.pro.service.main.SuggestService;
import com.qinghe.utils.AjaxObject;
import com.qinghe.utils.Page;

@Controller
@RequestMapping("/manager/suggest")
public class SuggestController {

	@Autowired
	@Qualifier("suggestServiceImpl")
	private SuggestService suggestService;

	private static final String VIEW = "manager/suggest/view";
	private static final String LIST = "manager/suggest/list";

	@RequiresPermissions("Suggest:delete")
	@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
	public @ResponseBody AjaxObject delete(@PathVariable Integer id) {
		suggestService.delete(id);

		return AjaxObject.newOk("删除反馈记录成功！");
	}

	@RequiresPermissions("Suggest:view")
	@RequestMapping(value = "/view/{id}", method = RequestMethod.GET)
	public String view(@PathVariable Integer id, Map<String, Object> map) {
		Suggest suggest = suggestService.get(id);
		
		map.put("suggest", suggest);
		return VIEW;
	}

	@RequiresPermissions("Suggest:show")
	@RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST })
	public String list(Page page, Map<String, Object> map) {
		List<Suggest> suggestList = suggestService.findByPage(page);

		map.put("page", page);
		map.put("suggestList", suggestList);

		return LIST;
	}

}
